<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>变量、常量、数据类型</title>
</head>
<body>
    <script>
        // 变量
        let str = "1. 这事一次测试！";
        console.log(str);
        console.log(typeof str);

        let len = 12;
        console.log(len);
        console.log(typeof len);

        // 常量
        const PI = 3.1415926;
        console.log(PI);
        console.log(typeof PI);

        // 数据类型

        // 1. string
        let s = "1. 这事一次测试！";
        console.log(s);
        console.log(typeof s);

        // 2. number
        let number = 12;
        console.log(number);
        console.log(typeof number);

        // 3. boolean
        let tv = true;
        console.log(tv);
        console.log(typeof tv);

        // 4. object
        let boy = {
            name: "老大",
            age: 45,
            weight: 60.5
        };
        console.log(boy);
        console.log(typeof boy);

        // 5. map 查询key快，typeof为object
        let m = new Map([
            ["name", "laoda"],
            ["age", 45]
        ]);
        console.log(m);
        console.log(typeof m);

        // 6. set 无序 唯一，typeof为object
        let nn = new Set([3,5,8]);
        nn.add(3);
        nn.add(1);
        console.log(nn);
        console.log(typeof nn);

        // 7. array 有序，不唯一，包含不同类型的元素，长度可变
        let arr = ["a", "b", "c", "d"];
        arr.push("e");
        arr.push("a");
        arr.push(0);
        console.log(arr);
        console.log("typeof", typeof arr);
        console.log("instanceof", arr instanceof Array); // 无法检测undefined, null, symbol
        console.log("constructor", arr.constructor === Array); // 无法检测undefined, null
        console.log("Object.prototype.toString.call", Object.prototype.toString.call(arr) === "[object Array]"); // 适用于所有类型的判断检测

        // 8. function
        function add(a, b) {
            return a + b;
        }
        console.log(add(3, 5));
        console.log(typeof add);

        // 9. class 类是一种蓝图或模板，用于创建具有相同属性和方法的对象
        class Person {
            constructor(name, age) {
                this.name = name;
                this.age = age;
            }

            info() {
                console.log("name=" + this.name + ", age=" + this.age);
            }
        }
        let p = new Person("laoda", 45);
        p.info();

        // 函数
        function getWeb() {
            let web = "www.baidu.com";
            console.log(web);
        }
        getWeb();

    </script>
</body>
</html>